<template>
  <el-card class="profile-card">
    个人中心
    <el-form ref="form" :model="user" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="user.username"></el-input>
      </el-form-item>

      <el-form-item label="邮箱">
        <el-input v-model="user.email"></el-input>
      </el-form-item>
      <el-form-item label="性别">
        <el-radio-group v-model="user.gender">
          <el-radio label="男"></el-radio>
          <el-radio label="女"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="手机号">
        <el-input v-model="user.phone"></el-input>
      </el-form-item>
      <el-form-item label="地址">
        <el-input v-model="user.address"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('form')">保存</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
import API from "../../api/API";
export default {
  name: "Personal",
  data() {
    return {
      user: {
        username: "",
        password: "",
        email: "",
        gender: "男",
        phone: "",
        address: "",
      },
    };
  },
  mounted() {
    API.getUserInfo()
      .then((response) => {
        this.user = response.data.data;
        console.log(this.user);
        console.log(response.data.data);
      })
      .catch((error) => {
        console.error(error);
      });
  },
  methods: {
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          alert("提交成功");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>

<style scoped>
.profile-card {
  width: 450px;
  margin: 10px auto;
  border-radius: 30px;
  border: 1px solid #ccc;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
}

.el-form--label-top .el-form-item__label {
  text-align: left;
}

.el-form-item__content {
  display: inline-block;
  align-items: center;
}

.el-form-item {
  margin-left: 12%;
  margin-top: 10px;
}

.el-input,
.el-radio,
.el-radio-group {
  width: 70%;
}

.el-button {
  width: 40%;
  margin-left: 15%;
}
</style>
